
<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>预览</title>
    <link href="/static/devtools30/layui/css/layui.css" rel="stylesheet" />
    <link href="/static/devtools30/css/devindexbase.css" rel="stylesheet" />
    <script src="/static/devtools30/js/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="/static/devtools30/layui/layui.all.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/devtoolCommon.js" type="text/javascript"></script>
    <link href="/static/devtools30/js/plugins/codemirror-5.14.2/theme/eclipse.css" rel="stylesheet" type="text/css" />
    <link href="/static/devtools30/js/plugins/codemirror-5.14.2/lib/codemirror.css" rel="stylesheet" />
    <script src="/static/devtools30/js/plugins/codemirror-5.14.2/lib/codemirror.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/plugins/codemirror-5.14.2/mode/sql/sql.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/plugins/codemirror-5.14.2/mode/javascript/javascript.js" type="text/javascript"></script>

    <style>
        /*顶部容器*/
        .tophead {
            height: 32px;
            border-bottom: 1px solid #F7F7F7;
            padding: 0 5px;
        }
        /*顶部输入框，下拉框去掉layui默认边距*/
        .tophead .layui-form-item {
            margin-bottom: 0px!important;
        }
        /*顶部输入框，下拉框左边文本样式*/
        .tophead .layui-form-label {
            padding: 0;
            line-height: 25px;
            width: auto;
        }
        /*顶部form块样式*/
        .tophead .layui-input-block {
            margin-left: 76px;
            min-height: 26px;
        }
        /*顶部输入框，下拉框设置高度*/
        .tophead .layui-input,
        .layui-select {
            height: 25px;
        }
        /*顶部下拉框设置子项高度*/
        .tophead .layui-form-select dl {
            top: 26px;
            padding: 0;
        }
        /*顶部下拉框设置子项内容高度*/
        .tophead .layui-form-select dl dd,
        .layui-form-select dl dt {
            line-height: 24px;
        }
        .tophead .layui-form-item {
            width: 165px;
        }
        /*顶部下拉框图标大小*/
        .tophead .layui-form-select .layui-edge {
            border-width: 4px;
        }
        /*搜索框左边距*/
        .tophead .search .layui-input-block {
            margin-left: 32px;
        }

        /*表格-----------------------------------*/


        /*表格边距*/

        .layui-table,
        .layui-table-view {
            margin: 0;
        }
        /*按钮高度大小*/
        .layui-btn {
            height: 26px;
            line-height: 26px;

        }
        /*按钮组-------------------------------*/
        /*按钮组左边框*/
        .layui-btn-group .layui-btn-primary:first-child {
            border-left: 1px solid #c9c9c9!important;
        }
        /*按钮组边框*/
        .layui-btn-group .layui-btn {
            border-left: 1px solid rgba(255, 255, 255, .5)!important;
        }
        .a
        {
            width:212px;height:45px;border:1px solid #b4b4b4;
        }
        .search-item{
            margin-right: 10px;
        }
        .edit_a{
            color: #1e9fff;
            text-decoration: underline;
            margin-right: 5px;
        }
    </style>

</head>
<body>
<div style="height: 100%;background: #F7F7F7;">
    <div  class="flex flex-align-center flex-jusity-betreen tophead backgroundf" style="margin:0 5px; padding: 2px 5px; ">

        <div lay-filter="parentbtn"  class="layui-form" id="recordListSearchForm">
            <input id="tempid" name="tempid" th:value="${tempid}" type="hidden" class="layui-input" />
            <div class="flex flex-align-center">
                <div  class="layui-form flex flex-align-center" id="appendInput"  lay-filter="searchInput" >


                </div>
            </div>
        </div>

        <div class="layui-btn-group btns" id="appendBtn">

        </div>
    </div>



    <div class="flex flex-jusity-start" id="tableDiv" style="height:100%;width: 100%;background: #F7F7F7;padding: 3px 0;margin: 0 5px;">
        <div class="backgroundf" style="float: left">
            <table  id="mygrid" lay-filter="mygrid"></table>
        </div>

        <div id="secondgrid" class="backgroundf" style="display: none;clear: both" >
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" style="margin: 0px 0; padding-left: 10px">
                <ul class="layui-tab-title">
                    <li class="layui-this" id="subtitle"></li>

                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <div  id="secondgriddiv">
                            <div class="flex flex-align-center flex-jusity-betreen tophead backgroundf">

                                <div class="layui-form" lay-filter="sonbtn" id="recordListSearchFormSon">
                                    <input id="SonTempid" name="SonTempid" th:value="${SonTempid}" type="hidden" class="layui-input" />
                                    <div class="flex flex-align-center">
                                        <div class="layui-form flex flex-align-center" id="appendSonInput">
                                        </div>
                                    </div>
                                </div>

                                <div  class="layui-btn-group btns" id="appendBtnSon">

                                </div>
                            </div>
                            <table  id="mygrid2"  lay-filter="mygrid2"></table>
                        </div>

                    </div>

                </div>
            </div>

        </div>
    </div>

</div>

<script>

    var patientRowData="";
    var sonRowData="";
    var height = dlCommon.getWinHeight()-10;
    var width=dlCommon.getWinWidth()-10;
    var jilian=[];
    var patientDataId="";
    var sonDataId="";
    //添加栏按钮
    var addButtonStr="";
    var addSonButtonStr="";
    $(function() {
        importLoad();

        initGrid();
        addInput();

        selectLoad();
        addSonInput();
    });

    function btnParentSearch(){

      var serchData = layui.form.val("parentbtn");
      layui.table.reload("mygrid", {
            url: "/V_SysFromPreviewController/getAllData?1=1[(${bitoken})]",
            where: serchData,
            loading: true,
      });

    }

    function btnSonSearch(){
        var serchData = layui.form.val("sonbtn");
        if(patientDataId==""){
            layui.layer.msg("请先选择主表数据");
            return;
        }
        layui.table.reload("mygrid2", {
            url: "/V_SysFromPreviewController/getSonAllData?1=1[(${bitoken})]&id="+patientDataId,
            where: serchData,
            loading: true,
        });
    }

    //导入预览加载
    function importLoad() {
        var importFlag='[(${importFlag})]'

        if(importFlag>0){
            addButtonStr+='<div class="dl-btn-group"> ' +
                '<button type="button" class="layui-btn layui-btn-primary">模板下载<span class="dl-caret"></span></button> ' +
                '<ul class="dl-dropdown-menu" style="min-width: 90px !important;">' +
                '<li><a href="javascript:;" onclick="importTempDownloadXls()">xls版本</a></li> ' +
                '<li><a href="javascript:;" onclick="importTempDownloadXlsx()">xlsx版本</a></li> ' +
                '</ul> ' +
                '</div>'

            addButtonStr+="<button type='button' class='layui-btn layui-btn-primary layui-btn-sm' id='uploadExample'>导入</button>";
        }
    }

    function importTempDownloadXls() {
        window.location.href="/V_SysFromPreviewController/downloadImportTemp?1=1[(${bitoken})]&tempid=[(${tempid})]&excelType=xls"
    }
    function importTempDownloadXlsx() {
        window.location.href="/V_SysFromPreviewController/downloadImportTemp?1=1[(${bitoken})]&tempid=[(${tempid})]&excelType=xlsx"
    }

    //下拉框联动加载
    function selectLoad() {
        if (jilian.length > 0) {
            $.each(jilian, function (i, item) {
                layui.form.on('select('+item.jlsrccode+')', function (data) {
                    if(data.value!='') {
                        dlCommon.getJSON("/V_SysFromPreviewController/getJiLianData?1=1[(${bitoken})]&value=" + data.value,
                            {"item": JSON.stringify(item)},
                            function (data) {
                                var str = "";
                                if (data.data != null) {
                                    var lxdataArr = data.data.split("/");
                                    $.each(lxdataArr, function (i, arr) {
                                        str += "<option value='" + arr.split("#")[0] + "'>" + arr.split('#')[1] + "</option>";
                                    })
                                }
                                $("#" + item.argname).html(str);
                                layui.form.render('select');
                        }, true)
                    }else {
                        $("#" + item.argname).html("<option value=''>请选择</option>");
                        layui.form.render('select');
                    }
                });

            })

        }
    }

    //查询控件加载
    function addInput(){
        var selectMapList = unescape('[(${selectMapList})]');
        var str="";
        var str="";
        var datetime=[];
        if('[(${searchBtnCfg})]'=="1") {
            if (selectMapList.length > 0) {
                loadSearchControl(JSON.parse(selectMapList),function(str,needShow){
                    if(needShow){
                        str += "<button style='margin-left:5px' onClick='btnParentSearch()' id='btnSubmit' class='button_login layui-btn' lay-submit lay-filter='btnSubmit'>确定</button>";
                    }
                    $("#appendInput").html(str);
                });
                btnParentSearch();
            }
        }



    }

    //子查询控件加载
    function addSonInput(){
        var SonSelectMapList = unescape('[(${SonSelectMapList})]');
        var str="";
        var str="";
        var datetime=[];
        if('[(${searchSonBtnCfg})]'=='1') {
            if (SonSelectMapList.length > 0) {
                loadSearchControl(JSON.parse(SonSelectMapList),function(str,needShow){
                    if(needShow){
                        str += "<button id='SonBtnSubmit' onclick='btnSonSearch()' style='margin-left: 5px' class='button_login layui-btn' lay-submit lay-filter='SonBtnSubmit'>确定</button>";
                    }
                    $("#appendSonInput").html(str);
                });
               // btnSonSearch();
            }
        }


    }
    //搜索控件
    function loadSearchControl(searchList,callback){
        var str="";
        var datetime=[];
        var defaultvalue={};
        var needShow=false;
        $.each(searchList, function (index, item) {
            switch (item.lxLable) {
                case "文本框":
                    // if (!item.isshow) {
                    //     break;
                    // }
                    needShow=needShow?needShow:item.isshow;
                    var displayValue=item.isshow?'':'none';
                    str += "<div class='layui-form-item search-item' style='display: "+displayValue+"'>";
                    str += " <label class='layui-form-label'>" + item.arglable + "</label>";
                    str += "<div class='layui-input-block'>";
                    str += "<input type='text' autocomplete=\"off\" id='" + item.argname + "' name='" + item.argname + "'  class='layui-input'>";
                    str += "</div>";
                    str += "</div>";
                    if(item.dvalue){
                      defaultvalue[item.argname]=item.dvalue;
                    }
                    break;
                case "下拉框":
                    // if (!item.isshow) {
                    //     break;
                    // }
                    needShow=needShow?needShow:item.isshow;
                    var displayValue=item.isshow?'':'none';
                    str += "<div class='layui-form-item search-item' style='display: "+displayValue+"'>";
                    str += "<label class='layui-form-label'>" + item.arglable + "</label>";
                    str += "<div class='layui-input-block'>";
                    str += "<select id='" + item.argname + "' name='" + item.argname + "' lay-filter='" + item.argname + "' style='width: 150px'>";
                    str += "<option value=''>请选择</option>";
                    var lxdataArr = item.lxdata.split("/");
                    $.each(lxdataArr, function (i, arr) {
                        if (arr != "") {
                            str += "<option value='" + arr.split("#")[0] + "'>" + arr.split('#')[1] + "</option>";
                        }
                    });
                    str += "</select>";
                    str += "</div>";
                    str += "</div>";

                    if (item.jlsrccode != "") {
                        jilian.push(item)
                    }
                    if(item.dvalue){
                        defaultvalue[item.argname]=item.dvalue;
                    }
                    break;
                case "日期选择":
                    // if (!item.isshow) {
                    //     break;
                    // }
                    needShow=needShow?needShow:item.isshow;
                    var displayValue=item.isshow?'':'none';
                    str += "<div class='layui-form-item search-item' style='display: "+displayValue+"'>";
                    str += " <label class='layui-form-label'>" + item.arglable + "</label>";
                    str += "<div class='layui-input-block'>";
                    str += "<input autocomplete=\"off\" type='text' id='" + item.argname + "' name='" + item.argname + "'  class='layui-input' readonly>";
                    str += "</div>";
                    str += "</div>";
                    datetime.push(item.argname)
                    if(item.dvalue){
                        defaultvalue[item.argname]=item.dvalue;
                    }
                    break;
            }
        })
        callback&&callback(str,needShow);

        layui.form.val("searchInput",defaultvalue)
        layui.form.render('select');

        $.each(datetime, function (i, arr) {
            var fmt='';
            fmt=defaultvalue[arr]&&defaultvalue[arr].length>10?'yyyy-MM-dd HH:mm:ss':fmt;
            fmt=defaultvalue[arr]&&defaultvalue[arr].length<=10&&defaultvalue[arr].length>7?'yyyy-MM-dd':fmt;
            fmt=defaultvalue[arr]&&defaultvalue[arr].length<=7&&defaultvalue[arr].length>5?'yyyy-MM':fmt;
            fmt=defaultvalue[arr]&&defaultvalue[arr].length<=5&&defaultvalue[arr].length>0?'yyyy':fmt;
            layui.use('laydate', function() {
                var laydate = layui.laydate;

                //常规用法
                laydate.render({
                    elem:"#"+arr
                    ,format:fmt
                });
            })
        })

    }

    //主表数据删除
    function delPatientData(dataid) {
        if (patientDataId==''&&!dataid){
            layui.layer.msg("请选中删除的数据");
            return;
        }
        patientDataId=dataid;
        dlCommon.layerConfirm("是否确定删除该数据？",function(){
            dlCommon.getJSON("/V_SysFromPreviewController/delData?1=1[(${bitoken})]&tempid=[(${tempid})]"+"&id="+patientDataId,{},function(res){
                if(!res.success){
                    dlCommon.layerError(res.msg);
                    return;
                }else {
                    btnParentSearch();
                    dlCommon.layerSuccess(res.msg);
                }

            },true)
        })



    }

    //主表数据新增
    function addPatientData() {
        var config = [(${config})];
        var url="/V_DevtFormDesignEntityController/saveAndUpdatePreview?1=1[(${bitoken})]&tempid=[(${tempid})]&callback=btnParentSearch&"+getmDefaultParms();
        dlCommon.layeropen(config.width,config.height,config.name,url);
    }
    //主表数据修改
    function updatePatientData(dataid) {
        var config = [(${config})];
        if (patientDataId==''&&!dataid){
            layui.layer.msg("请选中修改的数据");
            return;
        }
        patientDataId=dataid;
        var url="/V_DevtFormDesignEntityController/saveAndUpdatePreview?1=1[(${bitoken})]&tempid=[(${tempid})]&callback=btnParentSearch&dataid="+patientDataId+"&"+getmDefaultParms();
        dlCommon.layeropen(config.width,config.height,config.name,url);
    }

    //主表数据导出
    function importPatientData() {
        var serchData = layui.form.val("parentbtn");
        var param='';
        for (key in serchData) {
            if("tempid"==key){
                continue;
            }
            param = param+'&'+key+'='+serchData[key];
        }
        window.location.href="/V_SysFromPreviewController/patientDataImport?1=1[(${bitoken})]&tempid=[(${tempid})]"+param;
    }

    //子表数据删除
    function delSonData(dataid) {
        if (sonDataId==''&&!dataid){
            layui.layer.msg("请选中删除的数据");
            return;
        }
        sonDataId=dataid;
        dlCommon.layerConfirm("是否确定删除该数据？",function(){
            dlCommon.getJSON("/V_SysFromPreviewController/delSonData?1=1[(${bitoken})]&tempid=[(${tempid})]"+"&id="+sonDataId,{},function(res){
                if(!res.success){
                    dlCommon.layerError(res.msg);
                    return;
                }else {
                    btnSonSearch();
                    dlCommon.layerSuccess(res.msg);
                }

            },true)
        })

    }
    //子表数据新增
    function addSonData() {
        var url="/V_DevtFormDesignEntityController/saveAndUpdatePreview?1=1[(${bitoken})]&tempid=[(${SonTempid})]&callback=btnSonSearch";
        dlCommon.layeropen(650,500,"新增",url);
    }
    //子表数据修改
    function updateSonData(dataid) {
        if (sonDataId==''&&!dataid){
            layui.layer.msg("请选中修改的数据");
            return;
        }
        sonDataId=dataid;
        if (patientDataId==''){
            layui.layer.msg("请选中修改的数据");
            return;
        }
        var url="/V_DevtFormDesignEntityController/saveAndUpdatePreview?1=1[(${bitoken})]&tempid=[(${SonTempid})]&callback=btnSonSearch&dataid="+sonDataId;
        dlCommon.layeropen(650,500,"修改",url);

    }
    //子表数据导出
    function importSonData() {
        // var serchData = layui.form.val("parentbtn");
        var serchData = layui.form.val("sonbtn");
        var param='';
        for (key in serchData) {
            param = param+'&'+key+'='+serchData[key];
        }
        window.location.href="/V_SysFromPreviewController/patientDataImport?1=1[(${bitoken})]&tempid=[(${tempid})]"+param
    }

    //初始化grid
    function initGrid(){

        var tableMapListPatient = unescape('[(${tableMapListPatient})]');
        var tableMapListSon = unescape('[(${tableMapListSon})]');

        var tablePatientEntity =unescape('[(${tablePatientEntity})]')==''?"":JSON.parse(unescape('[(${tablePatientEntity})]'));
        var tableSonEntity = unescape('[(${tableSonEntity})]')==''?"":JSON.parse(unescape('[(${tableSonEntity})]'));

        //编辑栏 editFieldList
        var editFieldList = unescape('[(${editFieldList})]');
        var sonEditFieldList = unescape('[(${sonEditFieldList})]');
        

        var patinetTableWidth=75;
        var sonTableWidth=0;

        //表头
        var columnsP=[],columnsOneP=[];
        columnsOneP.push({
            field: '___xh', title: '序号',type:"numbers", align:"center",width: 40});
        patinetTableWidth+=40;
        $.each(JSON.parse(tableMapListPatient), function (index, item) {
            var fieldDefine = {field:item.field, title:item.title, width:item.width};
            patinetTableWidth+=item.width;
            columnsOneP.push(fieldDefine);
        })

        //编辑栏按钮
        var operaStr = "";
        var operaWidth=70;

        if ('[(${delBtnCfg})]'=='1'){
            operaStr += '<a onclick="delPatientData(\'#data-id#\')" href="javascript:;" class="edit_a">删除</a>';
            //operaStr += '<button type="button"  class="layui-btn layui-btn-normal layui-btn-xs layui_edit_btn" align="center">删除</button>';
            operaWidth+=20;
            patinetTableWidth+=20;
        }
        var thisAddButtonStr=addButtonStr;
        if('[(${addBtnCfg})]'=='1'){
            thisAddButtonStr+="<button type='button' onclick='addPatientData()' class='layui-btn layui-btn-primary layui-btn-sm'>新增</button>";
        }
        if('[(${editBtnCfg})]'=='1'){
            operaWidth+=20;
            patinetTableWidth+=20;
            operaStr += '<a onclick="updatePatientData(\'#data-id#\')" href="javascript:;" class="edit_a">编辑</a>';
            // operaStr+="<button type='button' onclick='updatePatientData()' class='layui-btn layui-btn-primary layui-btn-xs layui_edit_btn' align=\"center\">修改</button>";
        }
        if('[(${importBtnCfg})]'=='1'){
            thisAddButtonStr+="<button type='button' onclick='importPatientData()' class='layui-btn layui-btn-primary layui-btn-sm'>导出</button>";
        }


        $.each(JSON.parse(editFieldList), function (index, item) {
            switch (item.positionshow) {
                case "编辑栏":
                    if (item.useflagshow!="是") {
                        break;
                    }
                    operaStr += '<button type="button"  class="layui-btn layui-btn-normal layui-btn-xs layui_edit_btn" align="center">' + item.btnlabel + '</button>';
                    patinetTableWidth += 20;
                    operaWidth+=20;
                    break;
                case "添加栏":
                    if (item.useflagshow!="是") {
                        break;
                    }
                    thisAddButtonStr+="<button type='button' onclick='AddColumnFunction(\"";
                    thisAddButtonStr+=item.btnlabel;
                    thisAddButtonStr+="\")' class='layui-btn layui-btn-primary layui-btn-sm'>";
                    thisAddButtonStr+=item.btnlabel+"</button>";
                    break;
            }
        });
        //右上添加栏按钮
        $("#appendBtn").html(thisAddButtonStr);
        dlCommon.initDropButton();

        layui.upload.render({
            elem: "#uploadExample",//导入id
            url: "/V_SysFromPreviewController/toImport?1=1[(${bitoken})]&tempid=[(${tempid})]",
            size: '602400',
            accept: "file",
            exts: 'xls|xlsx',
            done: function (result) {
                layer.closeAll('loading');
                if (result.code == 0) {
                    initGrid();
                    layui.layer.msg(result.msg)
                }
                if (result.code != 0) {
                    layui.layer.msg("导入异常"+result.msg)
                }
            },
            before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layui.layer.load(); //上传loading
            },
            error: function(index, upload){
                layui.layer.closeAll('loading'); //关闭loading
            }
        });


        var fieldDefine = {
            field: 'opera', title: '操作', align:"center",width: operaWidth, templet: function (d) {
                return operaStr.replace(/#data-id#/g,d.id);
            }
        };
        if(operaStr!=""){
            columnsOneP.push(fieldDefine);
        }

        //表头组装完成
        columnsP.push(columnsOneP);
        

        if(tableMapListPatient.length>0){

            var d = {};
            var t = $('#recordListSearchForm [name]').serializeArray();
            $.each(t, function() {
                d[this.name] = this.value;
            });

            //分页
            var pageflag=false;
            if(tablePatientEntity!="" && tablePatientEntity.pageflag!=1){
                pageflag=true;
            }

            if (tablePatientEntity.location=='上下'){
                patinetTableWidth=width;
                height=height/2
                document.getElementById("tableDiv").removeAttribute("class");
            }
            if(tableMapListSon.length<=0){
                patinetTableWidth=width;
            }

            //第一个实例
            layui.table.render({
                elem: '#mygrid',
                height: height-36,
                width: patinetTableWidth,
                size: 'sm', //小尺寸的表格
                page: pageflag, //开启分页
                // url:"/V_SysFromPreviewController/getAllData?1=1[(${bitoken})]&tempid=[(${tempid})]",
                loading:true,
                cols: columnsP,
                where:d
            });
            if(tableMapListSon.length>0) {

                var columnsS=[],columnsOneS=[];
                columnsOneS.push({
                    field: '___xh', title: '序号',type:"numbers", align:"center",width: 40});
                $.each(JSON.parse(tableMapListSon), function (index, item) {
                    var fieldDefine = {field:item.field, title:item.title, width:item.width};
                    sonTableWidth+=item.width;
                    columnsOneS.push(fieldDefine);
                })


                var sonOperaStr = "";
                var sonOperaWidth=70;

                if ('[(${delSonBtnCfg})]'=='1'){
                    sonOperaStr+='<a href="javascript:;" onclick=\'delSonData("#data-id#")\' class="edit_a">删除</a>';
                    // sonOperaStr += '<button type="button" onclick="delSonData()" class="layui-btn layui-btn-normal layui-btn-xs layui_edit_btn" align="center">删除</button>';
                    sonOperaWidth+=20;
                }
                if('[(${addSonBtnCfg})]'=='1'){
                    addSonButtonStr+="<button type='button' onclick='addSonData()' class='layui-btn layui-btn-primary layui-btn-sm'>新增</button>";
                }
                if('[(${editSonBtnCfg})]'=='1'){
                    sonOperaWidth+=20;
                    sonOperaStr+='<a href="javascript:;" onclick=\'updateSonData("#data-id#")\' class="edit_a">编辑</a>';
                    // sonOperaStr+="<button type='button' onclick='updateSonData()' class='layui-btn layui-btn-primary layui-btn-sm'>修改</button>";
                }
                if('[(${importSonBtnCfg})]'=='1'){
                    addSonButtonStr+="<button type='button' onclick='importSonData()' class='layui-btn layui-btn-primary layui-btn-sm'>导出</button>";
                }


                $.each(JSON.parse(sonEditFieldList), function (index, item) {
                    switch (item.positionshow) {
                        case "编辑栏":
                            if (item.useflagshow!="是") {
                                break;
                            }
                            sonOperaStr+='<a href="javascript:;"  class="edit_a">' + item.btnlabel + '</a>';
                            // sonOperaStr += '<button type="button"  class="layui-btn layui-btn-normal layui-btn-xs layui_edit_btn" align="center">' + item.btnlabel + '</button>';
                            sonOperaWidth+=20;
                            break;
                        case "添加栏":
                            if (item.useflagshow!="是") {
                                break;
                            }
                            addSonButtonStr+="<button type='button' onclick='AddSonColumnFunction(\"";
                            addSonButtonStr+=item.btnlabel;
                            addSonButtonStr+="\")' class='layui-btn layui-btn-primary layui-btn-sm'>";
                            addSonButtonStr+=item.btnlabel+"</button>";
//                            addSonButtonStr+='<button type="button"  class="layui-btn layui-btn-primary layui-btn-sm">"'+item.btnlabel+'"</button>';
                            break;
                    }
                });
                $("#appendBtnSon").html(addSonButtonStr);

                var fieldDefine = {
                    field: 'opera', title: '操作', align:"center", width: sonOperaWidth, templet: function (d) {
                        return sonOperaStr.replace(/#data-id#/g,d.id);
                    }
                };
                if(sonOperaStr!=""){
                    columnsOneS.push(fieldDefine);
                }


                columnsS.push(columnsOneS);

                //分页
                var pageflag=false;
                if(tableSonEntity!="" &&tableSonEntity.pageflag!=1){
                    pageflag=true;
                }
                var subheight=height-40;

                //第2个实例
                if (tablePatientEntity.location=='上下'){
                    patinetTableWidth=0;
                    var movediv=document.getElementById("secondgriddiv");
                    $("#secondgrid").html("");
                    document.getElementById("secondgrid").appendChild(movediv);
                    $("#secondgriddiv").css("padding-top","5px");
                }else{
                    patinetTableWidth+=25;
                    subheight=subheight-80
                }

                $("#secondgrid").show();
                $("#subtitle").html(tableSonEntity.name);
                layui.table.render({
                    elem: '#mygrid2',
                    height: subheight,
                    width: width-patinetTableWidth,
                    size: 'sm', //小尺寸的表格
                    loading:false,
                    page: pageflag, //开启分页
                    cols: columnsS
                });
            }
            //单击表格
            dlCommon.layerTableOn('mygrid', function (obj) {

                var data={
                    id:obj.data.id,
                    tempid:'[(${tempid})]'
                };

                patientRowData=obj.data;

                patientDataId=obj.data.id;
                if('[(${tableMapListSon})]'!=''){
                    btnSonSearch();
                }

            });

            //单击表格
            dlCommon.layerTableOn('mygrid2', function (obj) {
                sonDataId=obj.data.id;
                sonRowData=obj.data;
            });
        }
    }
    
    function AddColumnFunction(id) {

        var postdata = patientRowData;

        var editFieldList = unescape('[(${editFieldList})]');

        $.each(JSON.parse(editFieldList), function (index, item) {
            var url = item.btnurl;
            if(item.btnlabel==id){

                $.each(postdata, function (index, item) {
                    url = url.replace("#"+index+"#",item);
                });

                var searchInput=layui.form.val("searchInput");
                for (key in searchInput) {
                    url = url.replace("#"+key+"#",searchInput[key]);
                }
                url=url.replace('#bitoken#','[(${bitoken})]');

                if (url.indexOf("#")>0) {
                    layui.layer.msg("URL包含参数传递 请选中数据");
                    return;
                }

                switch (item.actionshow) {
                    case "弹窗":
                        dlCommon.layeropen(item.width,item.height,item.btnlabel,url);
                        break;
                    case "不弹窗":
                        dlCommon.getJSON(url, postdata, function (data) {
                            layui.layer.msg(data.msg, {icon: 6});
                        }, true);
                        break;
                    case "新页面":
                        window.open(url)
                        break;
                }
            }
        });
    }


    function AddSonColumnFunction(id) {

        var postdata = sonRowData;

        var editFieldList = unescape('[(${sonEditFieldList})]');

        $.each(JSON.parse(editFieldList), function (index, item) {
            var url = item.btnurl;
            if(item.btnlabel==id){
                if (item.btnurl.indexOf("#")>0) {
                    if (postdata=='') {
                        layui.layer.msg("URL包含参数传递 请选中数据");
                        return;
                    }
                }

                $.each(postdata, function (index, item) {
                    url = url.replace("#"+index+"#",item);
                });
                url=url.replace('#bitoken#','[(${bitoken})]');

                switch (item.actionshow) {
                    case "弹窗":
                        dlCommon.layeropen(item.width,item.height,item.btnlabel,url);
                        break;
                    case "不弹窗":
                        dlCommon.getJSON(url, postdata, function (data) {
                            layui.layer.msg(data.msg);
                        }, true);
                        break;
                    case "新页面":
                        window.open(url)
                        break;
                }
            }
        });
    }

    function getmDefaultParms(){
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        var resStr="";
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0].startsWith("mDefaultValue_")){
                resStr=resStr+pair[0]+'='+pair[1];
            }
        }
        return resStr;
    }

    function getQueryVariable(variable){
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){
                return pair[1];
            }
        }
        return '';
    }
</script>
</body>
</html>
